const tagService = require('../service/tag.service');

class TagController {
  async create(ctx) {
    try {
      const result = await tagService.create(ctx.request.body.name);
      ctx.body = { errorCode: 0, data: result };
    } catch (error) {
      ctx.body = {
        errorCode: -1,
        data: error.message ? error.message : '未知错误',
      };
    }
  }
  async getList(ctx) {
    try {
      const { pageSize = 10, pageNumber = 1 } = ctx.query;
      const result = await tagService.getList({ pageSize, pageNumber });
      ctx.body = { errorCode: 0, data: result };
    } catch (error) {
      ctx.body = {
        errorCode: -1,
        data: error.message ? error.message : '未知错误',
      };
    }
  }
}

module.exports = new TagController();
